﻿// CWitsCfgDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "CWitsCfgDlg.h"
#include "afxdialogex.h"


// CWitsCfgDlg 对话框

IMPLEMENT_DYNAMIC(CWitsCfgDlg, CDialogEx)

CWitsCfgDlg::CWitsCfgDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_WITSCFGDLG, pParent)
{

}

CWitsCfgDlg::~CWitsCfgDlg()
{
}

void CWitsCfgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_cmbOut);
	DDX_Control(pDX, IDC_COMBO2, m_cmbIn);
	DDX_Text(pDX, IDC_OUTPORT, m_nOutPort);
	DDX_Text(pDX, IDC_INPORT, m_nInPort);
	DDX_Text(pDX, IDC_C1WITSCODE, m_strOut[0]);
	DDX_Text(pDX, IDC_C2WITSCODE, m_strOut[1]);
	DDX_Text(pDX, IDC_C3WITSCODE, m_strOut[2]);
	DDX_Text(pDX, IDC_IC4WITSCODE, m_strOut[3]);
	DDX_Text(pDX, IDC_NC4WITSCODE, m_strOut[4]);
	DDX_Text(pDX, IDC_IC5WITSCODE, m_strOut[5]);
	DDX_Text(pDX, IDC_NC5WITSCODE, m_strOut[6]);
	DDX_Text(pDX, IDC_TGWITSCODE, m_strOut[7]);
	DDX_Text(pDX, IDC_CO2WITSCODE, m_strOut[8]);
	DDX_Text(pDX, IDC_LAGDEPTH, m_strIn[0]);
	DDX_Text(pDX, IDC_PUMP1, m_strIn[1]);
	DDX_Text(pDX, IDC_PUMP2, m_strIn[2]);
	DDX_Text(pDX, IDC_PUMP3, m_strIn[3]);
	DDX_Text(pDX, IDC_LAGTIME, m_strIn[4]);
}


BEGIN_MESSAGE_MAP(CWitsCfgDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CWitsCfgDlg::OnBnClickedOk)
	ON_CBN_SELCHANGE(IDC_COMBO1, &CWitsCfgDlg::OnCbnSelchangeCombo1)
	ON_CBN_SELCHANGE(IDC_COMBO2, &CWitsCfgDlg::OnCbnSelchangeCombo2)
END_MESSAGE_MAP()


// CWitsCfgDlg 消息处理程序
BOOL CWitsCfgDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	for (int i = 0; i < 9; i++)
		m_strOut[i] = gl.ChromWits.strOutWits[i];
	for (int i = 0; i < 5; i++)
		m_strIn[i] = gl.ChromWits.strInWits[i];
	m_cmbOut.SetCurSel(gl.ChromWits.nOutMode);
	m_cmbIn.SetCurSel(gl.ChromWits.nInMode);
	m_nOutPort = gl.ChromWits.nOutPort;
	m_nInPort = gl.ChromWits.nInPort;
	if (gl.ChromWits.nOutAutoOpen == 1)
		((CButton*)GetDlgItem(IDC_CHECKOUT))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECKOUT))->SetCheck(0);

	if (gl.ChromWits.nInAutoOpen == 1)
		((CButton*)GetDlgItem(IDC_CHECKIN))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECKIN))->SetCheck(0);

	GetDlgItem(IDC_OUTIP)->SetWindowTextW(gl.ChromWits.strOutIP);
	GetDlgItem(IDC_INIP)->SetWindowTextW(gl.ChromWits.strInIP);

	if (gl.ChromWits.nOutMode == 0)
		GetDlgItem(IDC_OUTIP)->EnableWindow(FALSE);
	else
		GetDlgItem(IDC_OUTIP)->EnableWindow(TRUE);
	if (gl.ChromWits.nInMode == 0)
		GetDlgItem(IDC_INIP)->EnableWindow(FALSE);
	else
		GetDlgItem(IDC_INIP)->EnableWindow(TRUE);

	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

void CWitsCfgDlg::OnCbnSelchangeCombo1()
{
	// TODO: 在此添加控件通知处理程序代码
	int nCurSel = m_cmbOut.GetCurSel();
	if (nCurSel == 0)
		GetDlgItem(IDC_OUTIP)->EnableWindow(FALSE);
	else
		GetDlgItem(IDC_OUTIP)->EnableWindow(TRUE);
}


void CWitsCfgDlg::OnCbnSelchangeCombo2()
{
	// TODO: 在此添加控件通知处理程序代码
	int nCurSel = m_cmbIn.GetCurSel();
	if (nCurSel == 0)
		GetDlgItem(IDC_INIP)->EnableWindow(FALSE);
	else
		GetDlgItem(IDC_INIP)->EnableWindow(TRUE);
}


void CWitsCfgDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	gl.ChromWits.nOutMode = m_cmbOut.GetCurSel();
	gl.ChromWits.nInMode = m_cmbIn.GetCurSel();
	GetDlgItem(IDC_OUTIP)->GetWindowTextW(gl.ChromWits.strOutIP);
	GetDlgItem(IDC_INIP)->GetWindowTextW(gl.ChromWits.strInIP);
	gl.ChromWits.nOutPort = m_nOutPort;
	gl.ChromWits.nInPort = m_nInPort;

	if (((CButton*)GetDlgItem(IDC_CHECKOUT))->GetCheck() == 1)
		gl.ChromWits.nOutAutoOpen = 1;
	else
		gl.ChromWits.nOutAutoOpen = 0;
	if (((CButton*)GetDlgItem(IDC_CHECKIN))->GetCheck() == 1)
		gl.ChromWits.nInAutoOpen = 1;
	else
		gl.ChromWits.nInAutoOpen = 0;

	for (int i = 0; i < 9; i++)
		gl.ChromWits.strOutWits[i] = m_strOut[i];
	for (int i = 0; i < 5; i++)
		gl.ChromWits.strInWits[i] = m_strIn[i];

	gl.SaveSoftwareSetting();
	CDialogEx::OnOK();
}
